package com.cheyun.netsalev3.viewmodel

import android.content.Intent
import android.view.View
import androidx.lifecycle.Transformations
import com.cheyun.netsalev3.bean.StockParam
import com.cheyun.netsalev3.repository.StockPageRepository
import com.cheyun.netsalev3.view.StockDetailsActivity

class StockQueryListViewModel(var repository: StockPageRepository) : BaseViewModel() {
     var items= repository.loadAndroidData()

    val networkState = Transformations.switchMap(items) { repository.networkState }!!
    val total = Transformations.switchMap(items) { repository.total }!!

    fun onclickItem(view: View, item: StockParam) {
        var intent = Intent(view.context, StockDetailsActivity::class.java)
        intent.putExtra("id",item.id)
        view.context.startActivity(intent)
    }

    fun refresh(){
        repository.dataSourceFactory.sourceLiveData.value?.invalidate()
    }
}
